<%@page import="java.sql.Date"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ page import = "com.xiaonei.model.*,com.xiaonei.DAO.*,java.util.ArrayList,java.util.Iterator,com.util.*;" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>主贴</title>
</head>
<body>
<%--主题帖：
根据 --%>
<% 
PostDAOImpl postDAOImpl=new PostDAOImpl();
SchoolsDAOImpl schoolsDAOImpl=new SchoolsDAOImpl();
ArrayList<String> accountList=new ArrayList<String>();
ArrayList<Post> postList=new ArrayList<Post>();
String temp = request.getParameter("num");
int schoolNum =100;
schoolNum=Integer.parseInt(temp);
String schoolName=schoolsDAOImpl.getSchoolName(schoolNum);
out.print(""+schoolName+"的帖子列表:");
System.out.println("学校id:"+schoolNum);
accountList=schoolsDAOImpl.getAccountList(schoolNum);
System.out.println("accountList大小:"+accountList.size());
postList=postDAOImpl.postListbyAccountList(accountList);

//postList是一个帖子的集合，里面放有很多帖子，元素是Post对象；
//现在要做的是把每个帖子打印出来--然后在考虑要分页；
%>

<%
Pageable pageable=new Pageable(postList);
pageable.setCurrentPage(1);
pageable.setRowsCount(0);
pageable.setPageSize(5);

int pages=pageable.getTotalPages();
int listSize=postList.size();//共多少条记录
int pageSize=pageable.getPageSize();

System.out.println("这个postList总记录为:"+listSize);
System.out.println("这个postList的总页数为:"+pages);

String iPagetemp = request.getParameter("iPage");
int iPage=Integer.parseInt(iPagetemp);
System.out.println("当前页为:"+iPage);

pageable.setCurrentPage(iPage);
System.out.println("打印出当前页的第一个帖子的数组下标："+pageable.getRowsCount());

int currentPageRowsCount=pageable.getCurrentPageRowsCount();  //当前页的行数
System.out.println("当前页的记录数为:"+currentPageRowsCount);

int rowsCount=pageable.getRowsCount(); //当前页的第一行

%>

<%
Post post=new Post();
int reply=100;
String topic=null;
String author=null;
String account=null;

String theLastPeople=null;
String accountOftheLastPeople=null;
String time=null;
User1DAO user1DAO=new User1DAO();
int time1=0;


	for(int i=1;i<=currentPageRowsCount;i++,rowsCount++){    //在postList中是从0开始的；
		post=postList.get(rowsCount);
		reply=postDAOImpl.replyCountOfPost(post.post_num);
		
		account=postDAOImpl.getAccountOfAuthor(post.post_num);
		System.out.println(account);
		author=user1DAO.getNickName(account);
		System.out.println(author);
		
		accountOftheLastPeople=postDAOImpl.theLastPeople(post.post_num);
		System.out.println(accountOftheLastPeople);
		theLastPeople=user1DAO.getNickName(accountOftheLastPeople);
		System.out.println(theLastPeople);
		
		int topic_num=post.getTopic_num();
		TopicDAOImpl topicDAOImpl=new TopicDAOImpl();
		topic= topicDAOImpl.getContentOfTopic(topic_num);
		
		time=post.time;
		System.out.println(time);
		
		long nCurrentTime = System.currentTimeMillis();
		java.sql.Timestamp date=java.sql.Timestamp.valueOf(time);
		System.out.println(date);
		
		time1=((int)(nCurrentTime-date.getTime()))/(1000*60);
		
		
		System.out.println(nCurrentTime);
		
		
%>
<div onmouseover="style.backgroundColor='#f7f8ff'" onmouseout="style.backgroundColor='#ffffff'">
<table width="800" border="0" cellspacing="0" cellpadding="0" >
  	<tr>
    	<td width="500" rowspan="2">
    		<font color=red><%out.print(reply); %></font>
    		<%out.print(topic); %>
    		<a href="./tiezi.jsp?post_Num=<%=post.post_num %>"><%out.print(post.theme); %></a>
    	</td>
    	<td width="200" style="font-size:10px;COLOR: #c0c0c0;">作者：<a href="/xiaonei1227/homepage2.jsp?account=<%=account %>" ><%out.print(author); %></a></td>
    	<td rowspan="2" width ="100" style="font-size:10px;COLOR: #c0c0c0;"><%out.println(post.time); %></td>
  	</tr>
  	<tr>
    	<td width="200" style="font-size:10px;COLOR: #c0c0c0;">最后回复者:<a href="/xiaonei1227/homepage2.jsp?account=<%=accountOftheLastPeople %>" ><%out.print(theLastPeople); %></a></td>
  	</tr>
  	<tr>
    	<td colspan="3">内容:<%out.println(post.content); %></td>
  	</tr>
  	<tr>
    	<td colspan="3">图片url:<%out.println(post.imageUrl);%></td>
  	</tr>
  	<tr>
    	<td colspan="3" style="font-size:10px;COLOR: #c0c0c0;"><%out.print(time1);%>分钟以前</td>
  	</tr>
</table>
<hr />
</div>
	<%}%>


<!-- 分页的展示 start -->
每页5条&nbsp;共<%=listSize%>条&nbsp;共<%=pages%>页

<div>
<%
int pageShow;
%>

<%
	if(iPage==1) {
		%>
		<a href="./which-uni.jsp?num=<%=schoolNum %>&iPage=<%=1 %>">首页</a>
	<% }else{%>	
	<a href="./which-uni.jsp?num=<%=schoolNum %>&iPage=<%=iPage-1 %>"><%pageable.gotoPage(-2); %>上一页</a>
	<%} %>
<%for(pageShow=0;pageShow<pages;pageShow++){ %>
	<a href="./which-uni.jsp?num=<%=schoolNum %>&iPage=<%=pageShow+1 %>"><%=pageShow+1%>
	<%pageable.gotoPage(pageShow); %>
	</a>
	<%} %>

<%
	if(iPage==pages) {
		%>
		<a href="./which-uni.jsp?num=<%=schoolNum %>&iPage=<%=pages %>">末页</a>
	<% }else{%>	
	<a href="./which-uni.jsp?num=<%=schoolNum %>&iPage=<%=iPage+1 %>"><%pageable.gotoPage(-3);%>下一页</a>
	<%} %>
</div>
</body>
</html>